﻿using System;
using System.Threading;
using DevFramework.Business.Abstract;
using DevFramework.Business.DependencyResolvers.Ninject;
using DevFramework.Business.Abstract;

namespace DevFramework.MvcUI.Localize
{
    public class LocalizedString : MarshalByRefObject
    {
        /// <summary>
        /// {0} Language code: ex: tr-TR,en-EN
        /// {1} The Word Code in the table :  LangaugeWords
        /// </summary>
        private const string CacheNameKey = "Language.{0}.{1}";

        private readonly string _word;

        public override string ToString()
        {
            return _word;
        }

        public LocalizedString(string code)
        {
            var languageWordService = DependencyResolver<ILanguageWordService>.Resolve();
            var languageService = DependencyResolver<ILanguageService>.Resolve();

            var language = languageService.Get(Thread.CurrentThread.CurrentCulture.Name);
            var data = languageWordService.GetValue(language.Id, code);

            _word = data != null ? data.Value : code;
        }
    }
}